package com.yiyi.word_test.controller;

import com.yiyi.word_test.service.UserService;
import com.yiyi.word_test.util.ResultVOUtil;
import com.yiyi.word_test.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
public class UserController {

    // *********************************************
    // 无需在数据库中建用户表，仅需使用其openid即可
    // 在本地缓存或微信接口中获取即可

    @Autowired
    private UserService userService;

    // 获取openid
    @GetMapping("/getOpenId/{code}")
    public ResultVO getOpenId(@PathVariable("code") String code) {
        String openid = userService.getOpenId(code);

        if (openid == null) {
            return ResultVOUtil.error("获取openid失败");
        } else {
            return ResultVOUtil.success(openid);
        }
    }

}
